package com.arcgis.Viewer;

import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Menu;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.util.Date;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;

import com.esri.arcgis.beans.pagelayout.PageLayoutBean;
import com.esri.arcgis.carto.IElement;
import com.esri.arcgis.carto.IFeatureLayer;
import com.esri.arcgis.carto.IFeatureRenderer;
import com.esri.arcgis.carto.IGeoFeatureLayer;
import com.esri.arcgis.carto.ISimpleRenderer;
import com.esri.arcgis.carto.ITextElement;
import com.esri.arcgis.carto.SimpleRenderer;
import com.esri.arcgis.carto.TextElement;
import com.esri.arcgis.carto.esriViewDrawPhase;
import com.esri.arcgis.controls.CommandsEnvironment;
import com.esri.arcgis.controls.IMapControlEvents2Adapter;
import com.esri.arcgis.controls.IMapControlEvents2OnMouseDownEvent;
import com.esri.arcgis.controls.IPageLayoutControlDefault;
import com.esri.arcgis.controls.IPageLayoutControlEventsAdapter;
import com.esri.arcgis.controls.IPageLayoutControlEventsOnMouseDownEvent;
import com.esri.arcgis.controls.ISymbologyControlEventsAdapter;
import com.esri.arcgis.controls.ISymbologyControlEventsOnItemSelectedEvent;
import com.esri.arcgis.controls.ISymbologyStyleClass;
import com.esri.arcgis.controls.MapControl;
import com.esri.arcgis.controls.SymbologyControl;
import com.esri.arcgis.controls.esriSymbologyStyleClass;
import com.esri.arcgis.display.IColor;
import com.esri.arcgis.display.IFillSymbol;
import com.esri.arcgis.display.IFillSymbolProxy;
import com.esri.arcgis.display.ILineSymbol;
import com.esri.arcgis.display.ILineSymbolProxy;
import com.esri.arcgis.display.IMarkerSymbol;
import com.esri.arcgis.display.IMarkerSymbolProxy;
import com.esri.arcgis.display.IStyleGalleryClass;
import com.esri.arcgis.display.IStyleGalleryItem;
import com.esri.arcgis.display.IStyleGalleryItemProxy;
import com.esri.arcgis.display.ISymbol;
import com.esri.arcgis.display.RgbColor;
import com.esri.arcgis.display.ServerStyleGalleryItem;
import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.geometry.esriGeometryType;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.support.ms.stdole.Picture;

import sun.awt.resources.awt;
import com.arcgis.ValueChanged.*;

public class SymbolSelectorFrm extends JFrame implements ActionListener {
	private static final long serialVersionUID = 1L;
	String esriStylePath=null;
	private JPanel jPanel = null;
	// myImageObserver observer;
	JPanel panel_blow = null;
	JPanel panel_bottom = null;
	Icon icon;
	Image image;
	ImageIcon imageIcon = null;
	JLabel img_label = null;
	JLabel txt_color = null;
	JTextField txt_color_f = null;
	JLabel txt_size = null;
	JTextField txt_sizef = null;
	JLabel txt_width = null;
	JTextField txt_widthf = null;
	JLabel txt_angle = null;
	JTextField txt_anglef = null;
	JLabel txt_outerColor = null;
	JTextField txt_outerColor_f = null;
	JButton more_btn = null;
	JButton confirm_btn = null;
	JButton import_btn = null;
	JButton cancel_btn = null;
	Color textColor;
	IColor textIColor, outerColor;
	private MapControl main_mapControl;
	private PageLayoutBean pageLayout;
	private SymbologyControl symbologyControl;
	private IStyleGalleryItem styleGalleryItem; // 提供定义样式库中项目的成员的访问
	private CommandsEnvironment graphicProperties = null;
	private IFeatureLayer featureLayer; // 提供对控制要素图层的常见方面的成员的访问
	private ISimpleRenderer simpleRenderer; // 提供对控制渲染器的成员的访问，这些渲染器为每个要素绘制相同的符号。
	private IGeoFeatureLayer geoFeatureLayer; // 提供对控制要素图层的地理方面的成员的访问。
	String name;
	public SymbolSelectorFrm(MapControl map, MapControl vice_map, PageLayoutBean page, IFeatureLayer layer) {
		main_mapControl = map;
		pageLayout = page;
		featureLayer = layer;
		initialize();
		loadStyle();
		addListener();
		
	}

	public void initialize() {
		
		this.setBounds(770,0,480, 550);
		this.setContentPane(getJPanel());
		this.setTitle("符号选择器");
		// System.out.println("in");
	}

	public JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.add(getSymbologyControl());
			jPanel.add(getPanel_blow());
			jPanel.add(getPanel_bottom());
			jPanel.add(getMore_btn());
			jPanel.add(getCancel_btn());
			jPanel.add(getImport_btn());
			jPanel.add(getConfirm_btn());
			jPanel.setVisible(true);
		}
		return jPanel;
	}

	// 加载样式
	private void loadStyle() {
		try {
			// Get the ArcGIS Engine runtime, if it is available
			String runtimeHome = System.getenv("AGSENGINEJAVA");

			// If the ArcGIS Engine runtime is not available, then we can try
			// ArcGIS Desktop runtime
			if (runtimeHome == null) {
				runtimeHome = System.getenv("AGSDESKTOPJAVA");
			}

			// If no runtime is available, exit application gracefully
			if (runtimeHome == null) {
				if (System.getProperty("os.name").toLowerCase().indexOf("win") > -1) {
					System.err.println("You must have ArcGIS Engine Runtime or ArcGIS Desktop "
							+ "installed in order to execute this sample.");
					System.err.println("Install one of the products above, then re-run this sample.");
					System.err.println("Exiting execution of this sample...");
					System.exit(0);
				} else {
					System.err.println(
							"You must have ArcGIS Engine Runtime installed " + "in order to execute this sample.");
					System.err.println("Install the product above, then re-run this sample.");
					System.err.println("Exiting execution of this sample...");
					System.exit(0);
				}
			}

			// 获取ESRI.ServerStyle文件的相对路径
			esriStylePath = runtimeHome + "Styles" + File.separator + "ESRI.ServerStyle";

			File styleFile = new File(esriStylePath);

			// 测试以确保样式文件存在
			if (!styleFile.exists()) {
				System.err.println(
						"The ESRI.ServerStyle was not found in the following location: " + styleFile.getParent());
				System.err.println("Verify that ESRI.ServerStyle can be located in the specified folder.");
				System.err.println("If not present, try uninstalling your ArcGIS software and reinstalling it.");
				System.err.println("Exiting execution of this sample...");
				System.exit(0);
			}

			// 将ESRI.ServerStyle文件加载到SymbologyControl
			symbologyControl.loadStyleFile(esriStylePath);

			// 判断样式类型，加载相应的样式
			if (featureLayer.getFeatureClass().getShapeType() == esriGeometryType.esriGeometryPoint) { // 0维几何图形
				symbologyControl.setStyleClass(esriSymbologyStyleClass.esriStyleClassMarkerSymbols); // 标记符号
			} else if (featureLayer.getFeatureClass().getShapeType() == esriGeometryType.esriGeometryPolyline) { // 路径的有序集合
				symbologyControl.setStyleClass(esriSymbologyStyleClass.esriStyleClassLineSymbols); // 线符号
			} else if (featureLayer.getFeatureClass().getShapeType() == esriGeometryType.esriGeometryPolygon) {
				symbologyControl.setStyleClass(esriSymbologyStyleClass.esriStyleClassFillSymbols); // 填充符号

			}
		} catch (Exception err) {
			err.printStackTrace();
		}
	}

	public SymbologyControl getSymbologyControl() {
		if (symbologyControl == null) {
			symbologyControl = new SymbologyControl();
			symbologyControl.setBounds(new java.awt.Rectangle(20, 25, 300, 485));
		}
		return symbologyControl;
	}

	public JPanel getPanel_blow() {
		if (panel_blow == null) {
			panel_blow = new JPanel();
			img_label = new JLabel();

			img_label.setBounds(58, 30, 60, 60);
			panel_blow.setBounds(345, 40, 180, 120);
			panel_blow.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "预览",
					javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
					javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));

			panel_blow.setLayout(null);
			panel_blow.add(img_label);
			img_label.setVisible(true);
			panel_blow.setVisible(true);

		}
		return panel_blow;
	}

	public JPanel getPanel_bottom() {
		if (panel_bottom == null) {
			panel_bottom = new JPanel();
			panel_bottom.setBounds(345, 185, 180, 180);
			panel_bottom.setLayout(null);
			panel_bottom.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "设置",
					javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
					javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));

			txt_color = new JLabel();
			txt_color.setBounds(new java.awt.Rectangle(24, 25, 40, 20));
			txt_color.setText("颜色");

			txt_color_f = new JTextField();
			txt_color_f.setBounds(new java.awt.Rectangle(95, 25, 50, 20));
			txt_color_f.setEditable(false);

			txt_size = new JLabel();
			txt_size.setBounds(new java.awt.Rectangle(24, 55, 40, 20));
			txt_size.setText("大小");

			txt_sizef = new JTextField();
			txt_sizef.setBounds(new java.awt.Rectangle(80, 55, 80, 20));
			txt_sizef.setText("0");
			txt_sizef.setEditable(true);
			txt_sizef.addActionListener(this);

			txt_width = new JLabel();
			txt_width.setBounds(new java.awt.Rectangle(24, 85, 40, 20));
			txt_width.setText("宽度");

			txt_widthf = new JTextField();
			txt_widthf.setBounds(new java.awt.Rectangle(80, 85, 80, 20));
			txt_widthf.setText("0");
			txt_widthf.setEditable(true);
			
			txt_angle = new JLabel();
			txt_angle.setBounds(new java.awt.Rectangle(24, 115, 40, 20));
			txt_angle.setText("角度");

			txt_anglef = new JTextField();
			txt_anglef.setBounds(new java.awt.Rectangle(80, 115, 80, 20));
			txt_anglef.setText("0");
			txt_anglef.setEditable(true);

			txt_outerColor = new JLabel();
			txt_outerColor.setBounds(new java.awt.Rectangle(20, 135, 50, 40));
			txt_outerColor.setText("外框颜色");

			txt_outerColor_f = new JTextField();
			txt_outerColor_f.setBounds(new java.awt.Rectangle(95, 145, 50, 20));
			txt_outerColor_f.setEditable(true);

			
			panel_bottom.add(txt_color);
			panel_bottom.add(txt_color_f);
			panel_bottom.add(txt_size);
			panel_bottom.add(txt_sizef);
			panel_bottom.add(txt_width);
			panel_bottom.add(txt_widthf);
			panel_bottom.add(txt_angle);
			panel_bottom.add(txt_anglef);
			panel_bottom.add(txt_outerColor);
			panel_bottom.add(txt_outerColor_f);
			panel_bottom.setVisible(true);
		}
		return panel_bottom;
	}

	public JButton getMore_btn() {
		if (more_btn == null) {
			more_btn = new JButton();
			more_btn.setBounds(400, 380, 75, 22);
			more_btn.setText("更多符号");
			more_btn.setVisible(true);
			more_btn.addActionListener(this);
		}
		return more_btn;
	}

	public JButton getConfirm_btn() {
		if (confirm_btn == null) {
			confirm_btn = new JButton();
			confirm_btn.setBounds(400, 415, 75, 22);
			confirm_btn.setText("确定");
			confirm_btn.setEnabled(false);
			confirm_btn.addActionListener(this);
		}
		return confirm_btn;
	}
	
	public JButton getImport_btn(){
		if(import_btn==null){
			import_btn=new JButton();
			import_btn.setBounds(400, 445, 75, 22);
			import_btn.setText("导入地图");
			import_btn.addActionListener(this);
		}
		return import_btn;
	}

	public JButton getCancel_btn() {
		if (cancel_btn == null) {
			cancel_btn = new JButton();
			cancel_btn.setBounds(400, 475, 75, 22);
			cancel_btn.setText("取消");
			cancel_btn.addActionListener(this);
		}
		return cancel_btn;
	}

	
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		Runnable r = null;
		if (arg0.getSource() == confirm_btn) {
			r = new Runnable() {
				public void run() {
					try {
						if (styleGalleryItem == null)
							return;
						int rgb = txt_color_f.getBackground().getRed() + txt_color_f.getBackground().getGreen() * 256
								+ txt_color_f.getBackground().getBlue() * 65536;
						int outer_rgb = txt_outerColor_f.getBackground().getRed()
								+ txt_outerColor_f.getBackground().getGreen() * 256
								+ txt_outerColor_f.getBackground().getBlue() * 65536;
						IColor color = new RgbColor();
						color.setRGB(rgb);
						IColor outer_color = new RgbColor();
						outer_color.setRGB(outer_rgb);
						switch (symbologyControl.getStyleClass()) {
						// 标记符号
						case esriSymbologyStyleClass.esriStyleClassMarkerSymbols:
							Double size = Double.parseDouble(txt_sizef.getText());
							((IMarkerSymbol) styleGalleryItem.getItem()).setSize(size);
							Double angle = Double.parseDouble(txt_anglef.getText());
							((IMarkerSymbol) styleGalleryItem.getItem()).setAngle(angle);
							((IMarkerSymbol) styleGalleryItem.getItem()).setColor(color);
							break;
						// 线符号
						case esriSymbologyStyleClass.esriStyleClassLineSymbols:

							Double line_width = Double.parseDouble(txt_widthf.getText());
							((ILineSymbol) styleGalleryItem.getItem()).setWidth(line_width);
							((ILineSymbol) styleGalleryItem.getItem()).setColor(color);
							break;
						case esriSymbologyStyleClass.esriStyleClassFillSymbols:

							Double width = Double.parseDouble(txt_widthf.getText());
							((IFillSymbol) styleGalleryItem.getItem()).getOutline().setWidth(width);
							((IFillSymbol) styleGalleryItem.getItem()).setColor(color);

							((IFillSymbol) styleGalleryItem.getItem()).getOutline().setColor(outer_color);
							break;
						default:

							break;
						}
						PreviewImage();
						// 创建新的渲染器（作用：绘制图层）
						simpleRenderer = new SimpleRenderer();
						// 从样式GalleryItem中设置其符号
						// 过程：获取styleGalleryItem中的item,调用setSymbolByRef()绘制符号
						simpleRenderer.setSymbolByRef((ISymbol) styleGalleryItem.getItem()); // setSymbolByRef()：用于绘制每个要素的符号
						geoFeatureLayer = (IGeoFeatureLayer) featureLayer;
						// 将渲染器设置为igeoFeatureLayer
						geoFeatureLayer.setRendererByRef((IFeatureRenderer) simpleRenderer); //
						// 更改TOC控制侦听的事件：获取活动视图，修改视图对象时由客户端调用contentsChanged（）。
						main_mapControl.getActiveView().contentsChanged();
						// Refresh the display
						main_mapControl.refresh(esriViewDrawPhase.esriViewGeography, null, null);

						pageLayout.getActiveView().contentsChanged();
						pageLayout.refresh(esriViewDrawPhase.esriViewGeography, null, null);

					} catch (Exception err) {
						err.printStackTrace();
					}
				}

			};
			// this.setExtendedState(JFrame.ICONIFIED);
		}
		if (arg0.getSource() == cancel_btn) {
			styleGalleryItem = null;
			com.arcgis.Viewer.myFrame.flag=true;
			this.dispose();
		}
		Thread t = new Thread(r);
		t.start();
	}

	public void addListener() {
		
		try {
			// Get the CommandsEnvironment singleton
			graphicProperties = new CommandsEnvironment();

			// Create a new ServerStyleGalleryItem and set its name
			styleGalleryItem = new ServerStyleGalleryItem();

			// Set the commands environment marker symbol into the item
//			styleGalleryItem.setItem(graphicProperties.getMarkerSymbol());

			// Get the marker symbol style class
			ISymbologyStyleClass styleClass = getSymbologyControl()
					.getStyleClass2(esriSymbologyStyleClass.esriStyleClassMarkerSymbols);

			// Get the line symbol style class
			styleClass = getSymbologyControl().getStyleClass2(esriSymbologyStyleClass.esriStyleClassLineSymbols);

			// Set the commands environment line symbol into the item
//			styleGalleryItem.setItem(graphicProperties.getLineSymbol());

			// Get the fill symbol style class
			styleClass = getSymbologyControl().getStyleClass2(esriSymbologyStyleClass.esriStyleClassFillSymbols);

			// Set the commands environment fill symbol into the item
//			styleGalleryItem.setItem(graphicProperties.getFillSymbol());

			// Get the text symbol style class
			styleClass = getSymbologyControl().getStyleClass2(esriSymbologyStyleClass.esriStyleClassTextSymbols);

			// Set the commands environment text symbol into the item
//			styleGalleryItem.setItem(graphicProperties.getTextSymbol());

			symbologyControl.addISymbologyControlEventsListener(new ISymbologyControlEventsAdapter() {
				private static final long serialVersionUID = 1L;
				@SuppressWarnings("deprecation")
				public void onItemSelected(ISymbologyControlEventsOnItemSelectedEvent theEvent) {
					confirm_btn.setEnabled(true);
					// 获得选中的项目
					Double size = 0.0, angle = 0.0, width = 0.0;
					int rgb = 0, outer_rgb = 0;
					try {
						styleGalleryItem = new IStyleGalleryItemProxy(theEvent.getStyleGalleryItem());
						// 预览功能
						PreviewImage();

						switch (symbologyControl.getStyleClass()) {
						// 标记符号
						case esriSymbologyStyleClass.esriStyleClassMarkerSymbols:
							textIColor = (((IMarkerSymbol) styleGalleryItem.getItem()).getColor());
							rgb = textIColor.getRGB();
							angle = ((IMarkerSymbol) styleGalleryItem.getItem()).getAngle();
							size = ((IMarkerSymbol) styleGalleryItem.getItem()).getSize();
							
							break;
						case esriSymbologyStyleClass.esriStyleClassLineSymbols:
							textIColor = (((ILineSymbol) styleGalleryItem.getItem()).getColor());
							rgb = textIColor.getRGB();
							width = ((ILineSymbol) styleGalleryItem.getItem()).getWidth();
							
							break;
						case esriSymbologyStyleClass.esriStyleClassFillSymbols:
							outerColor = (((IFillSymbol) styleGalleryItem.getItem()).getColor());
							textIColor = (((IFillSymbol) styleGalleryItem.getItem()).getColor());
							outer_rgb = outerColor.getRGB();
							rgb = textIColor.getRGB();
							width = ((IFillSymbol) styleGalleryItem.getItem()).getOutline().getWidth();
							
							break;
						default:
							rgb = 0;
							break;

						}
						//IColor转换为Color
						Color c = new Color(rgb & 0xff, (rgb & 0xff00) / 0x100, (rgb & 0xff0000) / 0x10000);
						Color c_outer = new Color(outer_rgb & 0xff, (outer_rgb & 0xff00) / 0x100,
								(outer_rgb & 0xff0000) / 0x10000);
						txt_sizef.setText(size + "");
						txt_widthf.setText(width + "");
						txt_anglef.setText(angle + "");
						txt_color_f.setBackground(c);
						txt_outerColor_f.setBackground(c_outer);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				}
			});
			
			txt_color_f.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseClicked(MouseEvent arg0) {
					Color c = JColorChooser.showDialog(null, "Choose a Color", txt_color_f.getForeground());
					//int rgb=c.getRGB();
					if (c != null) {
						txt_color_f.setBackground(c);
						try {
							setColor(c);
							PreviewImage();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}

			});
			
			txt_outerColor_f.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseClicked(MouseEvent arg0) {
					textColor = JColorChooser.showDialog(null, "Choose a Color", txt_outerColor_f.getForeground());
					if (textColor != null) {
						txt_outerColor_f.setBackground(textColor);
					}
				}

			});

			
			
			more_btn.addMouseListener(new MouseAdapter(){
				public void mouseClicked(MouseEvent arg0){
					try {
						UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
						JFileChooser fc=new JFileChooser("D:/Program Files (x86)/ArcGIS10.2/Engine10.2/Styles");
						int n=fc.showDialog(null,"加载");
						if (n==JFileChooser.APPROVE_OPTION){
		                   //导入stylefile到SymbologyControl
		                    try {
		                    	symbologyControl.removeFile(esriStylePath);
		                    	esriStylePath=fc.getSelectedFile().getPath();
		                    	//System.out.println(esriStylePath);
								symbologyControl.loadStyleFile(esriStylePath);
								
							} catch (AutomationException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
		                }
					} catch (ClassNotFoundException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (InstantiationException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IllegalAccessException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (UnsupportedLookAndFeelException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			});
			
		} catch (AutomationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		import_btn.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e) {
				
				try {
					if (styleGalleryItem == null)
						return;
					int rgb = txt_color_f.getBackground().getRed() + txt_color_f.getBackground().getGreen() * 256
							+ txt_color_f.getBackground().getBlue() * 65536;
					int outer_rgb = txt_outerColor_f.getBackground().getRed()
							+ txt_outerColor_f.getBackground().getGreen() * 256
							+ txt_outerColor_f.getBackground().getBlue() * 65536;
					IColor color = new RgbColor();
					color.setRGB(rgb);
					IColor outer_color = new RgbColor();
					outer_color.setRGB(outer_rgb);
					switch (symbologyControl.getStyleClass()) {
					// 标记符号
					case esriSymbologyStyleClass.esriStyleClassMarkerSymbols:
						Double size = Double.parseDouble(txt_sizef.getText());
						((IMarkerSymbol) styleGalleryItem.getItem()).setSize(size);
						Double angle = Double.parseDouble(txt_anglef.getText());
						((IMarkerSymbol) styleGalleryItem.getItem()).setAngle(angle);
						((IMarkerSymbol) styleGalleryItem.getItem()).setColor(color);
						graphicProperties.setMarkerSymbol(new IMarkerSymbolProxy(styleGalleryItem.getItem()));
						break;
					// 线符号
					case esriSymbologyStyleClass.esriStyleClassLineSymbols:

						Double line_width = Double.parseDouble(txt_widthf.getText());
						((ILineSymbol) styleGalleryItem.getItem()).setWidth(line_width);
						((ILineSymbol) styleGalleryItem.getItem()).setColor(color);
						graphicProperties.setLineSymbol(new ILineSymbolProxy(styleGalleryItem.getItem()));
						
						break;
					case esriSymbologyStyleClass.esriStyleClassFillSymbols:

						Double width = Double.parseDouble(txt_widthf.getText());
						((IFillSymbol) styleGalleryItem.getItem()).getOutline().setWidth(width);
						((IFillSymbol) styleGalleryItem.getItem()).setColor(color);

						((IFillSymbol) styleGalleryItem.getItem()).getOutline().setColor(outer_color);
						graphicProperties.setFillSymbol(new IFillSymbolProxy(styleGalleryItem.getItem()));
						
						break;
					default:

						break;
					}
					
				} catch (UnknownHostException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			}
		});

	}

	public void PreviewImage() {
		Picture picture;
		try {
			picture = (Picture) symbologyControl.getStyleClass2(symbologyControl.getStyleClass())
					.previewItem(styleGalleryItem, 60, 60);
			image = picture.toImage();
			imageIcon = new ImageIcon(image);
			img_label.setIcon(imageIcon);
		} catch (AutomationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	public void setColor(Color c) throws AutomationException, IOException{
		IColor icolor;
		
		try {
			switch (symbologyControl.getStyleClass()) {
			case esriSymbologyStyleClass.esriStyleClassMarkerSymbols:
				icolor=((IMarkerSymbol)styleGalleryItem.getItem()).getColor();
				icolor.setRGB(c.getBlue() * 65536 + c.getGreen() * 256 + c.getRed());
				((IMarkerSymbol) styleGalleryItem.getItem()).setColor(icolor);
				
				break;
			case esriSymbologyStyleClass.esriStyleClassLineSymbols:
				icolor=((ILineSymbol) styleGalleryItem.getItem()).getColor();
				icolor.setRGB(c.getBlue() * 65536 + c.getGreen() * 256 + c.getRed());
				((ILineSymbol) styleGalleryItem.getItem()).setColor(icolor);
				break;
			case esriSymbologyStyleClass.esriStyleClassFillSymbols:
				icolor=((IFillSymbol) styleGalleryItem.getItem()).getColor();
				icolor.setRGB(c.getBlue() * 65536 + c.getGreen() * 256 + c.getRed());
				((IFillSymbol) styleGalleryItem.getItem()).setColor(icolor);
				((IFillSymbol) styleGalleryItem.getItem()).getOutline().setColor(icolor);;
				break;
			default:
				
				break;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public CommandsEnvironment getProperties(){
		return graphicProperties;
	}
}
